package com.example.projecttest.controller;

import com.example.projecttest.poji.Dept;
import com.example.projecttest.poji.Result;
import com.example.projecttest.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/depts")
@Slf4j
public class DeptController {
@Autowired
    private DeptService deptService;
    //请求方式Get,请求路径
@GetMapping
    public Result list(){
        log.info("查询所有数据");

         //调用service查询部门
   List <Dept> deptList= deptService.list();
        return Result.success(deptList);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
    //日志输出
        log.info("删除部门"+id);
        deptService.delet(id);
        return Result.success();
    }
    @PostMapping
    public Result insert(@RequestBody Dept dept) {
        log.info("插入数据" + dept);
        deptService.insert(dept);
        return Result.success();
    }
@GetMapping("/{id}")
    public Result sel(@PathVariable Integer id){
    log.info("查询id"+id);
   Dept dept=deptService.sel(id);
    return Result.success(dept);
}
@PutMapping
    public Result update(@RequestBody Dept dept){
    log.info("修改数据"+ dept);
    deptService.updata(dept);
    return Result.success();
}

}
